package com.wutuo.child.provider.dao;

import com.wutuo.child.api.request.ChildRequest;
import com.wutuo.child.api.request.ListChildRequest;
import com.wutuo.child.api.response.ChildResponse;
import com.wutuo.child.api.response.ParentChildResponse;
import com.wutuo.child.api.response.RollCallTaskResponse;
import com.wutuo.child.provider.domain.Child;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 孩子 Dao 层
 *
 * @author lvh
 * @version 1.0
 */
public interface ChildMapper extends BaseChildMapper {

    @SelectProvider(type = ChildSqlProvider.class, method = "lisForPage")
    @ResultType(value = ChildResponse.class) List<ChildResponse> lisForPage(
        ListChildRequest request);

    @SelectProvider(type = ChildSqlProvider.class, method = "list")
    @ResultType(value = ChildResponse.class) List<Child> list(ChildRequest request);

    @Update({"update child", "set ", "del_flag = #{delFlag,jdbcType=VARCHAR}",
        "where user_id = #{userId,jdbcType=BIGINT} and roster_id = #{rosterId,jdbcType=BIGINT} "})
    int delChild(Child record);

    @Update({"update task_detail", "set ", "state = #{state,jdbcType=VARCHAR}",
        "where task_id = #{callId,jdbcType=BIGINT} and user_id in (${childListId}) "})
    int updateLate(ChildRequest record);

    @Select({
        "select a.task_name as taskName,b.create_date as taskTime,b.state,a.create_by as teacherId,b.user_id as id ",
        "from task a, task_detail b ",
        "where a.id = b.task_id and user_id in (${childListId}) and b.state = #{state,jdbcType=VARCHAR}",
        "and b.del_flag = 1", " order by b.create_date desc"})
    List<RollCallTaskResponse> getRollCallTaskResponse(ListChildRequest record);

    @SelectProvider(type = ChildSqlProvider.class, method = "listRollCallTaskResponsePage")
    @ResultType(value = RollCallTaskResponse.class)
    List<RollCallTaskResponse> listRollCallTaskResponsePage(ListChildRequest record);

    @SelectProvider(type = ChildSqlProvider.class, method = "getParentByChildId")
    @ResultType(value = ParentChildResponse.class) List<ParentChildResponse> getParentByChildId(
        @Param("rosterIds") String rosterIds);

}